package file.day9_18.day02;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class Test02CopyFile {
    public static void main(String[] args) throws IOException {
        File file = new File(".");
        FileInputStream fis;
        FileOutputStream fos;

        File[] files = file.listFiles();//多文件操作
        for(File file1 : files){
            String name = file1.getName();
            byte[] data = new byte[1024*10];
            System.out.println(name);

            if(name.contains(".dat") || name.contains(".txt")){
                fis = new FileInputStream(name);
                fis.read(data);
                String[] names = name.split("\\.");
                name = names[0] + "_cp." + names[1];
                fos = new FileOutputStream(name);

                fos.write(data);
                fis.close();
                fos.close();
            }
            System.out.println("复制完毕");
        }

    }
}
